#!/bin/bash

#this script uplamples the data to 0.2mm isotropic resolution as recommended by LN2_LAYERS
#This is done to minimize partial volume effects of layers because of too wide bins in the histogram. 
#For more information see https://layerfmri.com/2019/02/22/how-many-layers-should-i-reconstruct/
#Or Uludag, K., Havlicek, M., 2021. Determining laminar neuronal activity from BOLD fMRI using a generative model. Progress in Neurobiology 102055. https://doi.org/10.1016/j.pneurobio.2021.102055

3dResample -dxyz 0.2 0.2 0.2 -rmode Cu -overwrite -prefix scaled_structure.nii.gz -input structure.nii.gz

3dResample -dxyz 0.2 0.2 0.2 -rmode Cu -overwrite -prefix scaled_cond_1a.nii.gz -input cond_1a.nii.gz
3dResample -dxyz 0.2 0.2 0.2 -rmode Cu -overwrite -prefix scaled_cond_2a.nii.gz -input cond_2a.nii.gz

3dResample -dxyz 0.2 0.2 0.2 -rmode Cu -overwrite -prefix scaled_cond_1b.nii.gz -input cond_1b.nii.gz
3dResample -dxyz 0.2 0.2 0.2 -rmode Cu -overwrite -prefix scaled_cond_2b.nii.gz -input cond_2b.nii.gz

#Note that this screws up the orientation of the header. while all upscaled data remain in the same space, the obligueness is not the same as before upsampling.

#In case you have Ants installed, you can also use the following command:
#ResampleImage 3 structure.nii.gz scaled_structure.nii.gz  0.2x0.2x0.2 0 3['l'] 6
#ResampleImage 3 cond_1a.nii.gz scaled_cond_1a.nii.gz  0.2x0.2x0.2 0 3['l'] 6
#ResampleImage 3 cond_2a.nii.gz scaled_cond_2a.nii.gz  0.2x0.2x0.2 0 3['l'] 6
#ResampleImage 3 cond_1b.nii.gz scaled_cond_1b.nii.gz  0.2x0.2x0.2 0 3['l'] 6
#ResampleImage 3 cond_2b.nii.gz scaled_cond_2b.nii.gz  0.2x0.2x0.2 0 3['l'] 6


######################################################
### Next thing to do it drawing rim in ITK-SNAP ######
######################################################


